/// <reference types="vitest/config" />

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'

//svg
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
//html
import { createHtmlPlugin } from 'vite-plugin-html'
import path from 'path'
// mock
import { viteMockServe } from 'vite-plugin-mock'

// https://vite.dev/config/
export default defineConfig({
  server: {
    port: 80,
    host: true,
  },
  test: {
    environment: 'happy-dom',
  },
  plugins: [
    viteMockServe({
      // 在哪个文件夹下编写模拟接口的代码
      mockPath: './src/mock',
      // 开发环境开启
      enable: true,
    }),
    createHtmlPlugin(),
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    //这里采用不自动引入组件样式，在main.ts中全局引入样式，如果二者反过来自定义样式会失效，自动引入样式在自定义样式之后,会被覆盖
    Components({
      resolvers: [VantResolver({ importStyle: false })],
    }),
    //打包svg地图
    createSvgIconsPlugin({
      // eslint-disable-next-line no-undef
      iconDirs: [path.resolve(process.cwd(), 'src/icons')],
    }),
  ],
  base: '/',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
